import { createStore } from 'vuex';
const store = createStore({
    state() {
        return {
            selectModel:"671B",
            model:{
                "32B":{
                    name:'32B',
                    modelName:'deepseek-r1:32b',
                    url:'/chat-stream',
                    key:'',
                    reasoning:'</think>'
                },
                "70B":{
                    name:'70B',
                    modelName:'deepseek-r1:70b',
                    url:'/chat-stream',
                    key:'',
                    reasoning:'</think>'
                },
                "671B":{
                    name:'671B',
                    modelName:'deepseek-r1:671b',
                    url:'/chat-stream',
                    key:'',
                    reasoning:'671b'
                }
            }
        };
    },
    mutations: {
        increment(state) {
            state.count++;  // 让计数器的值加 1
        },
        login(state, userData) {
            state.user.name = userData.name;
            state.user.isLoggedIn = true;
        }
    },
    // actions 就像是商场的调度员，它可以处理一些异步操作，然后再调用 mutations 来修改数据
    actions: {
        incrementAsync(context) {
            setTimeout(() => {
                context.commit('increment');  // 过 1 秒后调用 increment 这个 mutation
            }, 1000);
        },
        async loginAsync(context, userData) {
            // 模拟一个异步的登录请求
            const response = await fetch('/api/login', {
                method: 'POST',
                body: JSON.stringify(userData)
            });
            if (response.ok) {
                context.commit('login', userData);
            }
        }
    },
    // getters 就像是商场的查询台，组件可以通过它来获取 state 里的数据
    getters: {
        doubleCount(state) {
            return state.count * 2;  // 返回计数器值的两倍
        },
        isUserLoggedIn(state) {
            return state.user.isLoggedIn;  // 返回用户是否登录的状态
        }
    }
});

export default store;
